package hu.monitor.remoting.transport.socket;

import hu.monitor.remoting.transport.ServerEndpointAdapter;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Worker implements Runnable {
	private static Logger log = LoggerFactory.getLogger(Worker.class);

	private final Socket socket;
	private final ServerEndpointAdapter adapter;

	public Worker(final Socket socket, final ServerEndpointAdapter adapter) {
		this.socket = socket;
		this.adapter = adapter;
	}

	@Override
	public void run() {
		InputStream input = null;
		OutputStream output = null;
		try {
			input = this.socket.getInputStream();
			output = this.socket.getOutputStream();
			this.adapter.processRequest(input, output);
		} catch (final Exception ex) {
			log.error(ex.getMessage(), ex);
		} finally {
		//	IOUtils.closeQuietly(input);
		//	IOUtils.closeQuietly(output);
		//	IOUtils.closeQuietly(this.socket);
		}

	}

}
